package com.ibiaoke.boss.controller;

import com.ibiaoke.boss.entity.SysUser;
import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.goods.entity.Check;
import com.ibiaoke.goods.service.CheckService;
import com.ibiaoke.goods.service.XcxShopPriceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;

@Controller
public class BossCheckController  extends BaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private CheckService checkService;

    @Autowired
    private XcxShopPriceService xcxShopPriceService;


    @RequestMapping("/addChenk")
    @ResponseBody
    public Res addChenk(Check check, Integer shopId){
        SysUser user = getLoginUser();
        checkService.addCheck(user.getUserName(),shopId,check);
        logger.info("系统用户{}正在添加库存操作",user.getUserName());
        return Res.create();
    }

    @RequestMapping("/getGoodCount")
    @ResponseBody
    public Res getGoodCount(Integer goodId){
        Double stockNum =  xcxShopPriceService.getGoodCount(goodId);
        return  Res.create().addResponse("stockNum", stockNum);
    }


    @RequestMapping("/findCheckList")
    @ResponseBody
    public Res findCheckList(String goodName, Integer goodId, Date checkStartTime, Date checkEndTime, Integer shopId, Page page) {
        List<Check> goodCheckList =  checkService.findCheckList(goodName,goodId,checkStartTime,checkEndTime,shopId,page);
        return  Res.create().addResponse("goodCheckList", goodCheckList).addResponse("page",page);
    }

}